package org.fanximall.erp.framework.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author :  william
 * @version :  V1.0  created in 2024/4/23
 */
public class BaseDOMetaHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", getDate(), metaObject);
        this.setFieldValByName("createBy", getUser(), metaObject);
        this.setFieldValByName("updateTime", getDate(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", getDate(), metaObject);
        this.setFieldValByName("updateBy", getUser(), metaObject);
    }

    private Date getDate() {
       return new Date();
    }

    private String getUser() {
        return "admin";
    }
}
